package com.cnsunrun.framworksimple.activity;

import android.graphics.Bitmap;
import android.os.Environment;

import java.util.List;

/**
 * Created by WQ on 2017/7/29.
 */

public class Video2GifUtils {
    public static void video2Gif(String sourcePath,String aimPath){
        BitmapExtractor extractor = new BitmapExtractor();
        extractor.setFPS(4);
        extractor.setScope(0, 5);
        extractor.setSize(540, 960);
        List<Bitmap> bitmaps = extractor.createBitmaps(sourcePath);

//        String fileName = String.valueOf(System.currentTimeMillis()) + ".gif";
//        String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + fileName;
        GIFEncoder encoder = new GIFEncoder();
        encoder.init(bitmaps.get(0));
        encoder.start(aimPath);
        for (int i = 1; i <bitmaps.size(); i++) {
            encoder.addFrame(bitmaps.get(i));
        }
        encoder.finish();
    }

}
